package pkg_member

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

// DeleteJoinactivate 取消参加活动
// Author [piexlmax](https://github.com/piexlmax)
func (api *JoinactivateApi) DeleteJoinactivatec(c *gin.Context) {
	var req struct {
		ActivateID int `json:"activateid" binding:"required"`
		UserID     int `json:"userid" binding:"required"`
	}
	err := c.ShouldBindJSON(&req)
	if err != nil {
		global.GVA_LOG.Error("请求参数错误", zap.Error(err))
		response.FailWithMessage("请求参数错误", c)
		return
	}

	if err := joinactivateService.DeleteJoinactivateByActivityAndUser(req.ActivateID, req.UserID); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

func (api *JoinactivateApi) SearchCurrentIsJoinActivate(c *gin.Context) {
	var req struct {
		ActivateID int `json:"activateid" binding:"required"`
		UserID     int `json:"userid" binding:"required"`
	}
	err := c.ShouldBindJSON(&req)
	if err != nil {
		global.GVA_LOG.Error("请求参数错误", zap.Error(err))
		response.FailWithMessage("请求参数错误", c)
		return
	}

	found, err := joinactivateService.SearchCurrentIsJoinActivate(req.ActivateID, req.UserID)
	if err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
		return
	}

	if found {
		response.OkWithMessage("找到匹配的记录", c)
	} else {
		response.OkWithMessage("没有找到匹配的记录", c)
	}
}
